{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "00aa0502",
   "metadata": {},
   "source": [
    "* 本周主要内容：图像识别（人脸识别）\n",
    "* 日期：2023-03-013-week04\n",
    "* 记录人：刘石珍 "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c433610d",
   "metadata": {},
   "source": [
    "# 上周内容  \n",
    ">1.API文档阅读（考试）  \n",
    ">2. requests模块（考试）  \n",
    ">3.百度通用图像识别  "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "afcf891c",
   "metadata": {},
   "source": [
    "# 本周内容"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5e3c67bf",
   "metadata": {},
   "source": [
    "## 1.人脸识别概念和基础"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8f2a6449",
   "metadata": {},
   "source": [
    "## 2.人脸识别应用"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fdd7cca7",
   "metadata": {},
   "source": [
    "## 3.人脸识别实践-face++  \n",
    ">  1.人脸检测  \n",
    ">  2.人脸识别应用  \n",
    " \n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "686f3b27",
   "metadata": {},
   "source": [
    "# 人脸识别"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "dcbe41bd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'request_id': '1678679726,b5bfcdf6-8c6b-4580-8568-6d79a06a6b3d', 'time_used': 171, 'faces': [{'face_token': '6461d70f21a346bcc9abb14e9b73a4ef', 'face_rectangle': {'top': 217, 'left': 128, 'width': 212, 'height': 212}, 'attributes': {'gender': {'value': 'Male'}, 'age': {'value': 21}, 'smile': {'value': 0.831, 'threshold': 50.0}, 'headpose': {'pitch_angle': 6.281139, 'roll_angle': -4.4214725, 'yaw_angle': 2.531211}, 'blur': {'blurness': {'value': 0.43, 'threshold': 50.0}, 'motionblur': {'value': 0.43, 'threshold': 50.0}, 'gaussianblur': {'value': 0.43, 'threshold': 50.0}}, 'emotion': {'anger': 12.35, 'disgust': 0.017, 'fear': 0.047, 'happiness': 0.025, 'neutral': 79.294, 'sadness': 8.222, 'surprise': 0.046}, 'facequality': {'value': 91.981, 'threshold': 70.1}, 'beauty': {'male_score': 91.215, 'female_score': 88.927}}}], 'image_id': 'CK32OZiBwD+jB8ZbK4IsdA==', 'face_num': 1}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "Face++ 人脸检测\n",
    "'''\n",
    "\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('ccx.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "# 酬载准备\n",
    "payload = {\n",
    "    'api_key':'0-ePdEz8tHKevHo9diua4pfotiecQc5X',\n",
    "    'api_secret':'TgtmpFrb2Hmwr6gDpbBV8XBPC9ezB5YD',\n",
    "    'image_base64':img,\n",
    "    'return_attributes':'gender,age,smiling,headpose,facequality,emotion,blur,beauty'\n",
    "}\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=payload, headers=headers)\n",
    "if response:\n",
    "    print (response.json())\n",
    "else:\n",
    "    print(response.status_code)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "894f8de3",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
